import React from 'react';
import {inject, observer} from 'mobx-react';
import {Button} from 'antd';
import {WeaTop, WeaRightMenu, WeaTab, WeaSearchGroup, WeaInput, WeaSelect, WeaDialog, WeaBrowser, WeaAuth} from 'ecCom';
import {Form} from 'antd';
import {toJS} from 'mobx';


import * as API_WORKPLANSHAREPERSONALSTORE from '../../apis/workPlanSharePersonal';
import * as workplanUtil from '../../util/workplanUtil';
import {WeaLocaleProvider} from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
// @inject('workPlanSharePersonalStore')
// @observer

@inject('workPlanSharePersonalStore')
@observer
class AddWorkPlanShare extends React.Component {

  state = {
    //定义弹窗里的日程类型的相关数组
    dialogWorkplanKindOptions: []
  }

  //在第一次加载后获取日程类型的数组
  componentDidMount() {
    API_WORKPLANSHAREPERSONALSTORE.getSelectType().then((data) => {
      const workplanKindOptions = data.map((elem) => {
        return {...elem, selected: false};
      });
      this.setState({
        dialogWorkplanKindOptions: workplanKindOptions
      });
    });
  }

  render() {
    const workPlanSharePersonalStore = this.props.workPlanSharePersonalStore;

    return (
      <WeaAuth ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@ohtoeu`}
        icon={'icon-coms-schedule'}
        iconBgcolor={'#6D3CF8'}
        title={getLabel(384889, '添加日程共享')}
        visible={workPlanSharePersonalStore.ifShowAddDialog}
        conditions={toJS(workPlanSharePersonalStore.addWorkPlanShareCondition)}
        onOk={data => {
          workPlanSharePersonalStore.doSave(data);
        }}
        onCancel={() => {
          workPlanSharePersonalStore.closeAddDialog()
        }}
      >
      </WeaAuth>
    )
  };

  // 右键菜单数据
  getRightMenu() {
    // const {comsWeaTable} = this.props;
    // const selectedRowKeys = comsWeaTable.get('selectedRowKeys');
    const arr = [{
      icon: <i className='icon-coms-Preservation'/>,
      content: getLabel(30986, '保存'),
      onClick: key => {
        const workPlanSharePersonalStore = this.props.workPlanSharePersonalStore;
        // listDoingStore.doSearch();
        // listDoingStore.setShowSearchAd(false);

      }
    },];
    return arr
  }

  //顶部右侧按钮组合，按钮的功能逻辑待做
  getTopButtons() {
    const arr = [(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@oouus0@doSave`} type="primary">{getLabel(30986, '保存')}</Button>),];
    return arr;
  }

  //定义tab中点击高级搜索时的最下面的操作按钮集合
  getTabButtonsAd() {
    return [
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@zed4yy@doSearch`} type="primary" onClick={/*todo*/null}>{getLabel(197, '搜索')}</Button>),
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@x02m6s@doReset`} type="ghost" onClick={/*todo*/null}>{getLabel(2022, '重置')}</Button>),
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@qaztzd@doCancel`} type="ghost" onClick={/*todo*/null}>{getLabel(31129, '取消')}</Button>)
    ]
  }

  // 得到添加日程共享弹窗中的所有表单控件
  getWorkplanShareDialogControls() {
    const workPlanSharePersonalStore = this.props.workPlanSharePersonalStore;
    const FormItem = Form.Item;
    const shareTargetOptions = [
      {
        key: "1",
        selected: false,
        showname: `${getLabel(179, '人力资源')}`
      }, {
        key: "2",
        selected: false,
        showname: `${getLabel(33553, '分部')}`
      }, {
        key: "3",
        selected: false,
        showname: `${getLabel(27511, '部门')}`
      }, {
        key: "4",
        selected: false,
        showname: `${getLabel(122, '角色')}`
      }, {
        key: "5",
        selected: false,
        showname: `${getLabel(1340, '所有人')}`
      }, {
        key: "6",
        selected: false,
        showname: `${getLabel(15762, '所有上级')}`
      },
    ];
    const title = `${getLabel(81711, '基本信息')}`;
    let items = [
      {
        com:
          (<FormItem ecId={`${this && this.props && this.props.ecId || ''}_FormItem@n4psli@workplanType`}
            label={getLabel(16094, '日程类型')}
            labelCol={{span: `6`}}
            wrapperCol={{span: `18`}}>
            {(<WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@vcey6r@workplanType`} options={this.state.dialogWorkplanKindOptions}></WeaSelect>)}
          </FormItem>)
      },
      // {
      //     com:
      //         (<FormItem
      //             label={`共享对象`}
      //             labelCol={{span: `6`}}
      //             wrapperCol={{span: `18`}}>
      //             {(<WeaSelect
      //                 options={shareTargetOptions}
      //                 onChange={(selectedVal) => {workPlanSharePersonalStore.getControlsNextToShareTarget(selectedVal)}}
      //             />)}
      //         </FormItem>)
      // },
      // {
      //     com:
      //         (<FormItem
      //             // label={``}
      //             // labelCol={{span: `6`}}
      //             // wrapperCol={{span: `18`}}
      //          >
      //             <WeaBrowser {...workPlanSharePersonalStore.browserParams}></WeaBrowser>
      //         </FormItem>)
      // },
      // {com: <WeaSelect options={levelOptions}></WeaSelect>},
      // {com: <WeaSelect options={shareKindOptions}></WeaSelect>}
    ];

    // API_WORKPLANSHAREPERSONALSTORE.getSelectType().then((data) => {
    //     const workplanKindOptions = data.map((elem) => {
    //         return {...elem, selected: false};
    //     });
    //     this.setState({
    //         dialogWorkplanKindOptions: workplanKindOptions
    //     });
    // });

    return (
      <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@7ulm58`} title={title} items={items}/>
    )
  }

  //
  // changeData = (key) => {
  //     const { workPlanSharePersonalStore } = this.props;
  //     workPlanSharePersonalStore.setShowSearchAd(false);
  //     workPlanSharePersonalStore.doSearch({ viewcondition: key });
  // };
  //


}

export default AddWorkPlanShare
